package com.hankol.community.adapter

import android.annotation.SuppressLint
import android.view.MotionEvent
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.baselibrary.utils.GlideUtils
import com.baselibrary.utils.NumberUtils
import com.baselibrary.view.CircleImageView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.hankol.community.R
import com.hankol.community.bean.DataX
import com.baselibrary.utils.SpanUtils
import com.baselibrary.view.VipHeardImgView


/**
 *@author:hanke
 *2022/3/30
 *desc:
 */
class TopicGoodUserAdapter : BaseQuickAdapter<DataX, BaseViewHolder>(R.layout.item_good_user) {
    @SuppressLint("ClickableViewAccessibility")
    override fun convert(helper: BaseViewHolder, item: DataX) {
        helper.getView<VipHeardImgView>(R.id.civ_user_avatar).setData(item.icon,item.isFans == 1)
        helper.setText(R.id.tv_user_name, item.name)
        helper.setText(R.id.tv_like_number, "被点赞${NumberUtils.formatBigNum(item.allSupportNum.toString())}次")

        val subscribeButton: TextView = helper.getView(R.id.tv_good_user_focus)
        subscribeButton.isSelected = item.focusFans
        subscribeButton.text = if (subscribeButton.isSelected) "已关注" else "关注"

        val rvGoodUserCovers: RecyclerView = helper.getView(R.id.rv_user_topic_covers)
        rvGoodUserCovers.setOnTouchListener { _, event ->
            if (event.action == MotionEvent.ACTION_UP) {
                helper.getView<VipHeardImgView>(R.id.civ_user_avatar).performClick()
            }
            false
        }
        val topicGoodUserCoverAdapter = TopicGoodUserCoverAdapter()
        rvGoodUserCovers.adapter = topicGoodUserCoverAdapter
        topicGoodUserCoverAdapter.setNewData(item.coverList)

        helper.addOnClickListener(R.id.tv_good_user_focus)
        helper.addOnClickListener(R.id.civ_user_avatar)
    }
}